#include <head.h>

int main(int argc, char const *argv[])
{
    pid_t pidA,pidB;
    if(pidA = fork()==0)
    {
        FILE* file=fopen("1.txt","r");
        char buf[100];
        if(!file)
        {
            ERRLOG("文件打开错误");
            exit(1);
        }
       
        FILE* file_1=fopen("2.txt","w+");
        if(!file_1)
        {
            ERRLOG("文件创建/打开错误");
            exit(1);
        }
        fseek(file,49,SEEK_SET);
        long size = ftell(file);
        
        size_t bytesRead = fread(buf,1,size,file);
        fwrite(buf,1,bytesRead,file_1);
        fclose(file);
        fclose(file_1);
        exit(0);


    }
    else if(pidA<0)
    {
        ERRLOG("子进程创建失败");
        return 0;
    }
   
    if(pidB = fork()==0)
    {
        FILE* file=fopen("1.txt","r");
        char buf[100];
        if(!file)
        {
            ERRLOG("文件打开错误");
            exit(1);
        }
       
        FILE* file_1=fopen("3.txt","w+");
        if(!file_1)
        {
            ERRLOG("文件创建/打开错误");
            exit(1);
        }
       
        
        size_t bytesRead = fread(buf,1,49,file);
        fwrite(buf,1,bytesRead,file_1);
        fclose(file);
        fclose(file_1);
        exit(0);


    }
    else if(pidB<0)
    {
        ERRLOG("子进程创建失败");
        return 0;
    }
    waitpid(pidA,NULL,0);
    waitpid(pidB,NULL,0);
    while(1)
    {

    }
    
    

    return 0;
}
